<#--
    -ObjectMap
    -------------------------
    -OBJECT_CODE
    -OBJECT_CODE_UPPERCASE
    -OBJECT_CODE_LOWERCASE
    -OBJECT_CODE_BEAN_PATTERN
    -OBJECT_CODE_CAMLE_CASE

    -ObjectMap.attributesList
    -----------------------------------------
    -ATTRIBUTE_CODE
    -ATTRIBUTE_CODE_UPPERCASE
    -ATTRIBUTE_CODE_LOWERCASE
    -ATTRIBUTE_CODE_BEAN_PATTERN
    -ATTRIBUTE_CODE_CAMEL_CASE

    -ATTRIBUTE_CODE_DATATYPE
    -ATTRIBUTE_IS_PRIMARY_KEY
    -ATTRIBUTE_IS_FOREIGN_KEY
 -->


package com.ats.feeder.view.managedbeans.admin.${ObjectMap.OBJECT_CODE_BEAN_PATTERN};

import com.ats.feeder.model.entities.${ObjectMap.OBJECT_CODE_BEAN_PATTERN}.${ObjectMap.OBJECT_CODE_CAMLE_CASE};
import com.ats.feeder.model.exceptions.common.UpdateEntityException;
import com.ats.feeder.model.services.admin.${ObjectMap.OBJECT_CODE_BEAN_PATTERN}.Manage${ObjectMap.OBJECT_CODE_CAMLE_CASE}ServiceLocal;
import com.ats.feeder.view.common.FacesUtil;
import com.ats.feeder.view.common.MessageHandler;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;


@ManagedBean(name = "manage${ObjectMap.OBJECT_CODE_CAMLE_CASE}Bean")
@ViewScoped
public class Manage${ObjectMap.OBJECT_CODE_CAMLE_CASE}Bean implements  Serializable{

    @EJB
    ${ObjectMap.OBJECT_CODE_CAMLE_CASE}ServiceLocal manage${ObjectMap.OBJECT_CODE_CAMLE_CASE}Service;
    
    private List<${ObjectMap.OBJECT_CODE_CAMLE_CASE}> active${ObjectMap.OBJECT_CODE_CAMLE_CASE};
    private List<${ObjectMap.OBJECT_CODE_CAMLE_CASE}> inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE};
    private ${ObjectMap.OBJECT_CODE_CAMLE_CASE} selected${ObjectMap.OBJECT_CODE_CAMLE_CASE};
    

    @PostConstruct
    public void initialize() {
        setActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}(manage${ObjectMap.OBJECT_CODE_CAMLE_CASE}Service.getActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}());
        setInActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}(manage${ObjectMap.OBJECT_CODE_CAMLE_CASE}Service.getInActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}());
    }
        
    public void deactivateSelected${ObjectMap.OBJECT_CODE_CAMLE_CASE}(){
        String locale = FacesUtil.getLocaleLang();
        try {
            ${ObjectMap.OBJECT_CODE_CAMLE_CASE} _selected${ObjectMap.OBJECT_CODE_CAMLE_CASE} = getSelected${ObjectMap.OBJECT_CODE_CAMLE_CASE}();
            manage${ObjectMap.OBJECT_CODE_CAMLE_CASE}Service.deActivate${ObjectMap.OBJECT_CODE_CAMLE_CASE}(_selected${ObjectMap.OBJECT_CODE_CAMLE_CASE});
            inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}.add(_selected${ObjectMap.OBJECT_CODE_CAMLE_CASE});
            active${ObjectMap.OBJECT_CODE_CAMLE_CASE}.remove(active${ObjectMap.OBJECT_CODE_CAMLE_CASE}.indexOf(_selected${ObjectMap.OBJECT_CODE_CAMLE_CASE}));
        } catch (UpdateEntityException ex) {
           MessageHandler.addGenericErrorMessage(locale);
        }
        MessageHandler.addGenericSuccessMessage(locale);        
    }

    public void activateSelected${ObjectMap.OBJECT_CODE_CAMLE_CASE}(){
        String locale = FacesUtil.getLocaleLang();
        try {
            ${ObjectMap.OBJECT_CODE_CAMLE_CASE} _selected${ObjectMap.OBJECT_CODE_CAMLE_CASE} = getSelected${ObjectMap.OBJECT_CODE_CAMLE_CASE}();
            manage${ObjectMap.OBJECT_CODE_CAMLE_CASE}Service.activate${ObjectMap.OBJECT_CODE_CAMLE_CASE}(_selected${ObjectMap.OBJECT_CODE_CAMLE_CASE});
            active${ObjectMap.OBJECT_CODE_CAMLE_CASE}.add(_selected${ObjectMap.OBJECT_CODE_CAMLE_CASE});
            inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}.remove(inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}.indexOf(_selected${ObjectMap.OBJECT_CODE_CAMLE_CASE}));            
        } catch (UpdateEntityException ex) {
           MessageHandler.addGenericErrorMessage(locale);
        }        
        MessageHandler.addGenericSuccessMessage(locale); 
    }
    

    /**
     * @return the active${ObjectMap.OBJECT_CODE_CAMLE_CASE}
     */
    public List<${ObjectMap.OBJECT_CODE_CAMLE_CASE}> getActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}() {
        return active${ObjectMap.OBJECT_CODE_CAMLE_CASE};
    }

    /**
     * @param active${ObjectMap.OBJECT_CODE_CAMLE_CASE} the active${ObjectMap.OBJECT_CODE_CAMLE_CASE} to set
     */
    public void setActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}(List<${ObjectMap.OBJECT_CODE_CAMLE_CASE}> active${ObjectMap.OBJECT_CODE_CAMLE_CASE}) {
        this.active${ObjectMap.OBJECT_CODE_CAMLE_CASE} = active${ObjectMap.OBJECT_CODE_CAMLE_CASE};
    }

    /**
     * @return the inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}
     */
    public List<${ObjectMap.OBJECT_CODE_CAMLE_CASE}> getInActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}() {
        return inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE};
    }

    /**
     * @param inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE} the inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE} to set
     */
    public void setInActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}(List<${ObjectMap.OBJECT_CODE_CAMLE_CASE}> inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE}) {
        this.inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE} = inActive${ObjectMap.OBJECT_CODE_CAMLE_CASE};
    }

    /**
     * @return the selected${ObjectMap.OBJECT_CODE_CAMLE_CASE}
     */
    public ${ObjectMap.OBJECT_CODE_CAMLE_CASE} getSelected${ObjectMap.OBJECT_CODE_CAMLE_CASE}() {
        return selected${ObjectMap.OBJECT_CODE_CAMLE_CASE};
    }

    /**
     * @param selected${ObjectMap.OBJECT_CODE_CAMLE_CASE} the selected${ObjectMap.OBJECT_CODE_CAMLE_CASE} to set
     */
    public void setSelected${ObjectMap.OBJECT_CODE_CAMLE_CASE}(${ObjectMap.OBJECT_CODE_CAMLE_CASE} selected${ObjectMap.OBJECT_CODE_CAMLE_CASE}) {
        this.selected${ObjectMap.OBJECT_CODE_CAMLE_CASE} = selected${ObjectMap.OBJECT_CODE_CAMLE_CASE};
    }

  
}
